<template>
<el-card>
  <el-tabs v-model="activeName" @tab-click="handleClick">
<!--                                                   基本信息                                                          -->
    <el-tab-pane label="基本信息" name="first">
      <el-form :model="ruleForm" :rules="rules">
      <el-row type="flex" justify="space-between">

   <el-col :span="8">
     <el-form-item label="车辆编号" prop="id" label-width="120px">
       <el-input  disabled v-model="ruleForm.id"/>
     </el-form-item>
   </el-col>
  <el-col :span="8">
    <el-form-item label="车牌号码" prop="licensePlate" label-width="120px">
      <el-input  class="rule-input-edit" disabled v-model="ruleForm.licensePlate"/>
    </el-form-item>
  </el-col>
    <el-col :span="8">
      <el-form-item label="车辆类型" prop="truckTypeName" label-width="120px">
        <el-input disabled v-model="ruleForm.truckTypeName"/>
      </el-form-item>
    </el-col>

      </el-row>
      <el-row type="flex" justify="space-between">

          <el-col :span="8">
            <el-form-item label="车辆体积" prop="allowableLoad" label-width="120px">
              <el-input disabled v-model="ruleForm.allowableLoad"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="车牌载重" prop="allowableVolume" label-width="120px">
              <el-input disabled v-model="ruleForm.allowableVolume"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="GPSID" prop="deviceGpsId" label-width="120px">
              <el-input disabled v-model="ruleForm.deviceGpsId"/>
            </el-form-item>
          </el-col>

      </el-row>
      <el-row>
<!--        图片部分-->
<!--        <el-image style="width: 210px;height: 160px" :src="ruleForm.picture"></el-image>-->
        <el-form-item prop="picture">
          <el-col>图片信息</el-col>
   <template>
     <!--        没有图片-->
     <el-col v-if="this.ruleForm.picture==null">
       <img :src="src" style="width: 210px;height: 160px">
     </el-col>
     <!--        如果由图片-->
     <el-col v-else>
       <img :src="this.img1" style="width: 210px;height: 160px">
       <img :src="this.img2" style="width: 210px;height: 160px">
     </el-col>
   </template>
        </el-form-item>
      </el-row>
      </el-form>
    </el-tab-pane>
<!--                                                  行驶证信息                                -->
    <el-tab-pane label="行驶证信息" name="second">
      <el-form :model="forms" :rules="rule" >
        <el-row type="flex" justify="space-between">

          <el-col :span="8">
            <el-form-item label="行驶证号码：" prop="engineNumber" label-width="120px">
              <el-input disabled v-model="forms.engineNumber" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发动机号码：" prop="transportCertificateNumber" label-width="120px">
              <el-input  v-model="forms.transportCertificateNumber" class="rule-input-edit" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="注册时间：" prop="registrationDate" label-width="120px">
              <el-input v-model="forms.registrationDate" disabled />
            </el-form-item>
          </el-col>

        </el-row>
        <el-row type="flex" justify="space-between">

          <el-col :span="8">
            <el-form-item label="强制报废日：" prop="mandatoryScrap" label-width="120px">
              <el-input v-model="forms.mandatoryScrap" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="整备质量：" prop="overallQuality" label-width="120px">
              <el-input v-model="forms.overallQuality" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="检验有效期：" prop="mandatoryScrap" label-width="120px">
              <el-input v-model="forms.mandatoryScrap" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" >
          <el-col :span="8">
            <el-form-item label="核定载质量：" prop="allowableWeight"  label-width="120px">
              <el-input v-model="forms.allowableWeight" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="有效期：" prop="validityPeriod"  label-width="120px">
              <el-input disabled v-model="forms.validityPeriod" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!--        图片部分-->
          <!--        <el-image style="width: 210px;height: 160px" :src="ruleForm.picture"></el-image>-->
          <el-form-item >
            <el-col>图片信息</el-col>
            <template>
              <!--        没有图片-->
              <el-col v-if="this.ruleForm.picture==null">
                <img :src="src" style="width: 210px;height: 160px">
              </el-col>
              <!--        如果由图片-->
              <el-col v-else>
                <img :src="this.img3" style="width: 210px;height: 160px">
                <img :src="this.img4" style="width: 210px;height: 160px">
              </el-col>
            </template>
          </el-form-item>
        </el-row>
      </el-form>
    </el-tab-pane>
  </el-tabs>
</el-card>
</template>

<script>
import { getTruckDetailApi, getTruckDetailApis } from '@/api/vehicle'

export default {
  name: 'detailsa',
  data () {
    return {
      activeName: 'first',
      src: '',
      ruleForm: {
        id: '',
        licensePlate: '',
        truckTypeName: '',
        allowableVolume: '',
        allowableLoad: '',
        deviceGpsId: '',
        picture: ''
      },
      rules: {
        id: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        licensePlate: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        truckTypeName: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        allowableVolume: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        allowableLoad: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        deviceGpsId: [{ required: true, message: '请输入活动名称', trigger: 'blur' }]
      },
      img1: '',
      img2: '',
      forms: {
        allowableWeight: '',
        engineNumber: '',
        expirationDate: '',
        id: '',
        mandatoryScrap: '',
        outsideDimensions: '',
        overallQuality: '',
        picture: '',
        registrationDate: '',
        transportCertificateNumber: '',
        validityPeriod: ''
      },
      rule: {
        allowableWeight: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        engineNumber: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        expirationDate: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        id: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        mandatoryScrap: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        outsideDimensions: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        overallQuality: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        picture: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        registrationDate: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        transportCertificateNumber: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        validityPeriod: [{ required: true, message: '请输入活动名称', trigger: 'blur' }]
      },
      img3: '',
      img4: ''

    }
  },
  created () {
    this.getTruckDetail()
  },
  methods: {
    handleClick () {
      this.getTruckDetailApisaa()
    },
    // 获取获取车辆详情
    async getTruckDetail (id) {
      const res = await getTruckDetailApi(this.$route.query.id)
      // console.log(res)
      // console.log(this.$route.query.id)
      this.ruleForm = res.data
      console.log(this.ruleForm)
      this.arr = this.ruleForm.picture.split(',')
      this.img1 = this.arr[0]
      this.img2 = this.arr[1]
    },
    // 获取行驶证信息
    async getTruckDetailApisaa () {
      const res = await getTruckDetailApis(this.$route.query.id)
      console.log(res)
      this.forms = res.data
      console.log(this.forms.picture)
      this.img3 = this.forms.picture.split(',')[0]
      this.img4 = this.forms.picture.split(',')[1]
    }
  }
}
</script>
<style>
.el-input__inner{
  background-color: #fff;
}
</style>
